<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>用户列表-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">用户列表</div>
		<div class="right">
			<div class="input-group left w250">
		    	<input type="text" id="keyword" value="{$keyword}" class="form-control" placeholder="按用户名/手机号/员工号搜索" autocomplete="off">
	    		<span class="input-group-btn">
					<button class="btn found_btn" type="button">搜索</button>
				</span>
			</div>
			<a href="javascript:;" class="btn hr_btn ml10">同步HR数据</a>
		</div>
	</div>
	<div id="content">
		<div class="filter">
			<div class="filter-item">
				<div class="filter-title">所属中心：</div>
				<ul class="filter-order">
					<li <if condition="$center_id eq -10">class="current"</if>>
						<a href="__APP__/System/user_list/keyword/{$keyword}/center_id/-10/status/{$status}">全部</a>
					</li>
					<foreach name="center_list" item="vo">
					<li <if condition="$center_id eq $vo['id']">class="current"</if>>
						<a href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$vo['id']}/status/{$status}">{$vo['first_name']}</a>
					</li>
					</foreach>
				</ul>
			</div>
			<div class="filter-item">
				<div class="filter-title">用户状态：</div>
				<ul class="filter-order">
					<li <if condition="$status eq 1">class="current"</if>>
						<a href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/status/1">在职</a>
					</li>
					<li <if condition="$status eq -1">class="current"</if>>
						<a href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/status/-1">离职</a>
					</li>
				</ul>
			</div>
		</div>
		<div class="table-scrollx">
			<table class="table table-bordered table-hover">
				<tr class="table-header fixed-table-header">
					<td width="100">
						<select name="username" class="form-control" style="width:85px;">
							<option value="-10"<if condition="$username eq -10"> selected</if>>姓名</option>
							<foreach name="result1" item="vo">
							<option value="{$vo['username']}"<if condition="$username eq $vo['username']"> selected</if>>{$vo['username']}</option>
							</foreach>
						</select>
					</td>
					<td width="50">员工号</td>
					<td width="98">手机号</td>
					<td width="44">邮箱</td>
					<td>部门</td>
					<td>
						<select name="position_id" class="form-control">
							<option value="-10"<if condition="$position_id eq -10"> selected</if>>职位</option>
							<foreach name="result_position" item="vo">
							<option value="{$vo['position_id']}"<if condition="$position_id eq $vo['position_id']"> selected</if>>{$vo['position_descr']}</option>
							</foreach>
						</select>
					</td>
					<td>
						<select name="rank_id" class="form-control" style="width:60px;">
							<option value="-10"<if condition="$rank_id eq -10"> selected</if>>职级</option>
							<foreach name="result_rank" item="vo">
							<option value="{$vo['rank_id']}"<if condition="$rank_id eq $vo['rank_id']"> selected</if>>{$vo['rank_descr']}</option>
							</foreach>
						</select>
					</td>
					<td>
						<select name="permissions_id" class="form-control">
							<option value="-10"<if condition="$permissions_id eq -10"> selected</if>>权限包</option>
							<foreach name="result8" item="vo">
							<option value="{$vo['id']}"<if condition="$permissions_id eq $vo['id']"> selected</if>>{$vo['permissions_name']}</option>
							</foreach>
						</select>
					</td>
					<td>
						<select name="auditor" class="form-control" style="width:85px;">
							<option value="-10"<if condition="$auditor eq -10"> selected</if>>审核人</option>
							<foreach name="result10" item="vo">
							<option value="{$vo['leader_uid']}"<if condition="$auditor eq $vo['leader_uid']"> selected</if>>{$vo['leader_name']}</option>
							</foreach>
						</select>
					</td>
					<td width="100">更新日期</td>
					<td width="54">管理</td>
				</tr>
				<if condition="$result eq NULL">
				<tr>
					<td colspan="11" class="text-center">暂无相关内容</td>
				</tr>
				</if>
				<foreach name="result" item="vo">
				<tr>
					<td>{$vo['username']}</td>
					<td>{$vo['empl_id']}</td>
					<td>{$vo['mobilephone']}</td>
					<td>
						<if condition="$vo['email'] neq NULL">
							<a href="mailto:{$vo['email']}" data-toggle="tooltip" data-placement="right" title="发送邮件"><i class="glyphicon glyphicon-envelope"></i></a>
						</if>
					</td>
					<td width="27%" style="min-width:150px" title="{$vo.descr}">{$vo['deps']}</td>
					<td>{$vo['position_descr']}</td>
					<td>{$vo['rank_descr']}</td>
					<td>{$vo['permissions_name']}</td>
					<td>{$vo['audit_user']}</td>
					<td>{$vo['update_date']|substr=0,10}</td>
					<td class="nowrap">
						<if condition="$vo['status'] eq 1">
						<a href="__APP__/System/user_list_edit/center_id/{$center_id}/username/{$username}/position_id/{$position_id}/rank_id/{$rank_id}/permissions_id/{$permissions_id}/status/{$status}/auditor/{$auditor}/id/{$vo['id']}" class="mr5" data-toggle="tooltip" data-placement="left" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>
						</if>
					</td>
				</tr>
				</foreach>
			</table>
		</div>
		<div class="pages">{$page}</div>
	</div>
</div>
<!--对话框-->
<div class="modal fade" id="myModal_startup">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>启用提示框</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body"></div>
			<div class="modal-footer">
				<button type="button" class="btn ok_startup">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<!--对话框-->
<div class="modal fade" id="HR_modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>同步HR数据</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<table class="table table-bordered">
					<tr>
						<td width="100" class="text-right"><strong><span class="asterisk">*</span>更新日期</strong></td>
						<td>
							<input type="text" class="form-control w100 date" value="{$today}" readonly autocomplete="off">
							<span class="error-item" style="display: none;">必填项</span>
						</td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn hr_sub">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function() {
	//hr
	$('.hr_btn').click(function(){
		$('#HR_modal').modal();
		$('#HR_modal .error-item').hide();
	})
	$('.hr_sub').click(function(){
		var tag = true,
			date = $('#HR_modal .date'),
			val = date.val();
		if(val==''){
			date.next('.error-item').show();
			tag = false;
		}
		if(tag){
			$.ajax({
				type:"POST",
				dataType:'json',
				async:false,
				data:{"date":val},
				url:"__APP__/Hr/system_timing_update_dep",
				success:function(data){
					if(data.status){
						$.ajax({
							type:"POST",
							dataType:'json',
							async:false,
							data:{"date":val},
							url:"__APP__/Hr/system_timing_update_user",
							success:function(data){
								if(data.status){
									success_pop(data.status,data.msg);
								}
							}
						});
					}
				}
			})
		}
	})
	//搜索
	$(".found_btn").keywordSearch("__APP__/System/user_list/keyword/$keyword/center_id/{$center_id}/username/{$username}/position_id/{$position_id}/rank_id/{$rank_id}/permissions_id/{$permissions_id}/status/{$status}");

	//同步
	$(".sync_btn").click(function(){
		$.ajax({
			type:"POST",
			dataType:'json',
			async:false,
			url:"__APP__/Hr/system_timing_update_dep",
			success:function(data){
				if(data.status){
					$.ajax({
						type:"POST",
						dataType:'json',
						async:false,
						url:"__APP__/Hr/system_timing_update_user",
						success:function(data){
							if(data.status){
								success_pop(data.status,data.msg);
							}
						}
					});
				}
			}
		});
	});

	//表头选择
	$(document).on("change","[name='username']",function(){
		var val = $(this).val();
		window.location.href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/username/"+val+"/position_id/{$position_id}/rank_id/{$rank_id}/permissions_id/{$permissions_id}/status/{$status}/auditor/{$auditor}";
	});
	$(document).on("change","[name='position_id']",function(){
		var val = $(this).val();
		window.location.href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/username/{$username}/position_id/"+val+"/rank_id/{$rank_id}/permissions_id/{$permissions_id}/status/{$status}/auditor/{$auditor}";
	});
	$(document).on("change","[name='permissions_id']",function(){
		var val = $(this).val();
		window.location.href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/username/{$username}/position_id/{$position_id}/rank_id/{$rank_id}/permissions_id/"+val+"/status/{$status}/auditor/{$auditor}";
	});
	$(document).on("change","[name='position_id']",function(){
		var val = $(this).val();
		window.location.href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/username/{$username}/position_id/"+val+"/rank_id/{$rank_id}/permissions_id/{$permissions_id}/status/{$status}/auditor/{$auditor}";
	});
	$(document).on("change","[name='rank_id']",function(){
		var val = $(this).val();
		window.location.href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/username/{$username}/position_id/{$position_id}/rank_id/"+val+"/permissions_id/{$permissions_id}/status/{$status}/auditor/{$auditor}";
	});
	$(document).on("change","[name='auditor']",function(){
		var val = $(this).val();
		window.location.href="__APP__/System/user_list/keyword/{$keyword}/center_id/{$center_id}/username/{$username}/position_id/{$position_id}/rank_id/{$rank_id}/permissions_id/{$permissions_id}/status/{$status}/auditor/"+val;
	});
	
	//禁用
	$(".cancle_user").ajaxModal({"title_text":"确认提示框","body_text":"您确定要禁用该用户吗？","url":"__APP__/System/user_list_ajax_status","data":{"id":"uid","action":"action"}});

	//启用
	$(".startup_user").click(function(){
		var uid = $(this).attr("uid"),
			leave = $(this).attr("leave"),
			$body = $("#myModal_startup .modal-body");
		
		$("#myModal_startup").modal({
			"show":true,
			"backdrop":"static"
		}).find(".ok_startup").attr({"uid":uid,"leave":leave});
		
		if(leave==1){
			$.ajax({
				type:"POST",
				dataType:'json',
				async:false,
				data:{"id":uid,"action":"department"},
				url:"__APP__/System/user_list_ajax_status",
				success:function(data){
					var $select = "姓名："+data.username+"<br>";
					$select += "<div class='mt10'>部门：";
					$select += "<select class='form-control w200 modal-department'>";
					$select += "<option value='-10' selected>请选择</option>";
					for(var i=0;i<data.department.length;i++){
						$select += "<option value="+data.department[i].id+">"+data.department[i].department+"</option>";
					}
					$select += "</select>";
					$select += "<span class='error-item'>必填项</span>";
					$select += "</div>";
					
					$body.html($select);
				}
			});
		}else{
			$body.html("您确定要启用该用户吗?");
		}
	});

	$(".ok_startup").on("click",function(){
		var uid = $(this).attr("uid"),
			tag = true;
		
		$("select.modal-department").each(function(){
			if($(this).val()==-10){
				$(this).next(".error-item").show();
				tag = false;
			}
		});
		
		if(tag){
			var $department_id = $("select.modal-department").val();
			
			$("#myModal_startup").hide();
			$.ajax({
				type:"POST",
				dataType:'json',
				async:false,
				data:{"id":uid,"action":"on","department_id":$department_id},
				url:"__APP__/System/user_list_ajax_status",
				success:function(data){
					success_pop(data.status,data.msg);
				}
			});
		}
	});

	//取消错误提示
	$('#HR_modal .date').click(function(){
		$(this).next(".error-item").hide();
	})
	$("#myModal_startup").on("change","select.modal-department",function(){
		$(this).next(".error-item").hide();
	});
});
</script>
</body>
</html>